﻿/********************************************************************
	日期:2022/4/28 21:29
	名称:ServerSession
	邮箱:yunnibbd@163.com
	作者:yunni
	描述:网络会话连接
*********************************************************************/

using PENet;
using PEProtocol;

public class ServerSession : PESession<GameMsg>{
    public int sessionID = 0;

    //到了30秒就干掉本客户端
    private int heart = 0;
    
    
    /**
     * 加入本次经过上次检测的时间秒数
     */
    public void CheckHeart(int seconds){
        heart += seconds;
        if (heart > 30){
            OnDisConnected();
            Close();
        }
    }

    /// <summary>
    /// 收到指定的心跳包后重置心跳计时
    /// </summary>
    public void ResetHeart(){
        this.heart = 0;
    }

    protected override void OnConnected(){
        sessionID = ServerRoot.Instance.GetSessionID();
        PECommon.Log("SessionID:" + sessionID + " Client Connect");
    }

    protected override void OnDisConnected(){
        PECommon.Log("SessionID:" + sessionID + " Client Offine");
        LoginSys.Instance.ClearOffineData(this);
    }

    protected override void OnReciveMsg(GameMsg msg){
        PECommon.Log("SessionID:" + sessionID + "RecvPack CMD" + ((CMD) msg.cmd).ToString());
        NetSvc.Instance.AddMsgQue(this, msg);
    }
}